package 删除相邻数字的最大分数;

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    static int N = 10010;
    static int[] sum = new int[N];
    static int[] f = new int[N];
    static int[] g = new int[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for (int i = 1; i <= n; i++) {
            int x = in.nextInt();
            sum[x] += x;
        }
        for (int i = 1; i <= N-1; i++) {
            f[i] = g[i - 1] + sum[i];
            g[i] = Math.max(g[i - 1], f[i - 1]);
        }
        System.out.println(Math.max(f[N-1], f[N-1]));
    }
}

